package cn.itsource.org.service.impl;

import cn.itsource.basic.AjaxResult;
import cn.itsource.basic.PageList;
import cn.itsource.org.domain.Employee;
import cn.itsource.org.mapper.EmployeeMapper;
import cn.itsource.org.query.EmployeeQuery;
import cn.itsource.org.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class EmployeeServiceImpl implements IEmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public Employee queryOne(Long id) {
        return employeeMapper.loadOne(id);
    }

    @Override
    public List<Employee> queryAll() {
        return employeeMapper.loadAll();
    }

    @Override
    @Transactional
    public void add(Employee employee) {
        employeeMapper.insert(employee);
    }

    @Override
    @Transactional
    public void update(Employee employee) {
        employeeMapper.update(employee);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        employeeMapper.delete(id);
    }

    @Override
    public PageList<Employee> queryPage(EmployeeQuery employeeQuery) {
        //查询总条数
        Long count = employeeMapper.queryCount(employeeQuery);
        //查询分页数据
        List<Employee> rows = employeeMapper.queryData(employeeQuery);
        //封装成pageList
        return new PageList<>(count,rows);
    }

    @Override
    @Transactional
    public AjaxResult patchDelete(List<Long> ids) {
        return employeeMapper.patchDelete(ids);
    }
}
